﻿<UserControl x:Class="CardPlay.Client.Views.PileView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:Interactivity="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" 
             xmlns:Behaviors="clr-namespace:CardPlay.Client.Behaviors" 
             xmlns:Presentation="clr-namespace:CardPlay.Model.GameModel.Presentation;assembly=CardPlay.Model" 
             xmlns:CardModel="clr-namespace:CardPlay.Model.CardModel;assembly=CardPlay.Model" 
             xmlns:Converters="clr-namespace:CardPlay.Client.Converters" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <Storyboard x:Key="ShowHotCue">
            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="HotCue" Storyboard.TargetProperty="Visibility">
                <DiscreteObjectKeyFrame KeyTime="0">
                    <DiscreteObjectKeyFrame.Value>
                        <Visibility>Visible</Visibility>
                    </DiscreteObjectKeyFrame.Value>
                </DiscreteObjectKeyFrame>
            </ObjectAnimationUsingKeyFrames>
            <DoubleAnimation To="1" Duration="0" Storyboard.TargetName="Glow" Storyboard.TargetProperty="(DropShadowEffect.Opacity)" />
        </Storyboard>
        
        <Storyboard x:Key="HideHotCue">
            <DoubleAnimation To="0" Duration ="0:0:0.18" AccelerationRatio="0.4" Storyboard.TargetName="Glow" Storyboard.TargetProperty="(DropShadowEffect.Opacity)" />
            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="HotCue" Storyboard.TargetProperty="Visibility">
                <DiscreteObjectKeyFrame KeyTime="1">
                    <DiscreteObjectKeyFrame.Value>
                        <Visibility>Hidden</Visibility>
                    </DiscreteObjectKeyFrame.Value>
                </DiscreteObjectKeyFrame>
            </ObjectAnimationUsingKeyFrames>
        </Storyboard>

        <Style x:Key="baseBorder" TargetType="Rectangle">
            <Style.Setters>
                <Setter Property="RadiusX" Value="8" />
                <Setter Property="RadiusY" Value="8" />
                <Setter Property="StrokeThickness" Value="3" />
                <Setter Property="Stroke" Value="#40D0D0D0" />
                <Setter Property="StrokeDashCap" Value="Round" />
            </Style.Setters>
        </Style>
        
        <Style x:Key="cardSite" TargetType="Rectangle">
            <Style.Setters>
                <Setter Property="RadiusX" Value="6" />
                <Setter Property="RadiusY" Value="6" />
            </Style.Setters>
        </Style>

        <DataTemplate x:Key="pileBase" DataType="{x:Type Presentation:EmptyPileCue}" >
            <Control Name="baseBorder" />
            <DataTemplate.Triggers>
                <!-- Outline -->
                <DataTrigger Binding="{Binding}">
                    <DataTrigger.Value>
                        <Presentation:EmptyPileCue>Outlined</Presentation:EmptyPileCue>
                    </DataTrigger.Value>
                    <Setter TargetName="baseBorder" Property="Template">
                        <Setter.Value>
                            <ControlTemplate>
                                <Rectangle Style="{StaticResource baseBorder}" StrokeDashArray="0.3,1" />
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </DataTrigger>

                <!-- Foundation -->
                <DataTrigger Binding="{Binding}">
                    <DataTrigger.Value>
                        <Presentation:EmptyPileCue>Foundation</Presentation:EmptyPileCue>
                    </DataTrigger.Value>
                    <Setter TargetName="baseBorder" Property="Template">
                        <Setter.Value>
                            <ControlTemplate>
                                <Rectangle RadiusX="8" RadiusY="8" StrokeThickness="5" Stroke="#80D0D0D0" />
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </DataTrigger>

                <!-- Redeal -->
                <DataTrigger Binding="{Binding}">
                    <DataTrigger.Value>
                        <Presentation:EmptyPileCue>Redeal</Presentation:EmptyPileCue>
                    </DataTrigger.Value>
                    <Setter TargetName="baseBorder" Property="Template">
                        <Setter.Value>
                            <ControlTemplate>
                                <Grid>
                                    <Rectangle Style="{StaticResource baseBorder}" Fill="#00000000" />
                                    <Ellipse Width="110" Height="110" StrokeThickness="11" Stroke="#8000E000" />
                                </Grid>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </DataTrigger>

                <!-- No deal -->
                <DataTrigger Binding="{Binding}">
                    <DataTrigger.Value>
                        <Presentation:EmptyPileCue>NoRedeal</Presentation:EmptyPileCue>
                    </DataTrigger.Value>
                    <Setter TargetName="baseBorder" Property="Template">
                        <Setter.Value>
                            <ControlTemplate>
                                <Grid>
                                    <Rectangle Style="{StaticResource baseBorder}" />
                                    <Path Width="80" Height="80" StrokeThickness="12" Stroke="#FFF00000" StrokeStartLineCap="Round" StrokeEndLineCap="Round" >
                                        <Path.Data>
                                            <PathGeometry>
                                                <PathGeometry.Figures>
                                                    <PathFigure StartPoint="10,10">
                                                        <LineSegment Point="70,70"></LineSegment>
                                                    </PathFigure>
                                                    <PathFigure StartPoint="70,10">
                                                        <LineSegment Point="10,70"></LineSegment>
                                                    </PathFigure>
                                                </PathGeometry.Figures>
                                            </PathGeometry>
                                        </Path.Data>
                                    </Path>
                                </Grid>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </DataTrigger>

                <!-- CardSite -->
                <DataTrigger Binding="{Binding}">
                    <DataTrigger.Value>
                        <Presentation:EmptyPileCue>CardSite</Presentation:EmptyPileCue>
                    </DataTrigger.Value>
                    <Setter TargetName="baseBorder" Property="Template">
                        <Setter.Value>
                            <ControlTemplate>
                                <Rectangle Style="{StaticResource baseBorder}" />
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </DataTrigger>

            </DataTemplate.Triggers>
        </DataTemplate>

        <Converters:RankToStringConverter x:Key="RankConverter" />
        <Converters:VisibiltyToBoolConverter x:Key="HideIfTrue" Inverted="True" Not="True" />
    </UserControl.Resources>
    <Canvas>
        <Grid Canvas.Left="{Binding Path=BaseBounds.X}" Canvas.Top="{Binding Path=BaseBounds.Y}" 
              Width="{Binding Path=BaseBounds.Width}" Height="{Binding Path=BaseBounds.Height}" 
              Visibility="{Binding IsElevated, Converter={StaticResource HideIfTrue}}">

            <!-- Base -->
            <ContentControl Content="{Binding EmptyCue}" ContentTemplate="{StaticResource pileBase}" />

            <!-- Cues -->
            <DockPanel ClipToBounds="True" Margin="4" IsHitTestVisible="False">
                <ItemsControl DockPanel.Dock="Left" Width="40" ItemsSource="{Binding Path=BaseCues.Suits}" >
                    <ItemsControl.ItemTemplate>
                        <DataTemplate DataType="{x:Type CardModel:Suit}">
                            <Path x:Name="SuitFigure" Fill="Black" Margin="7,10,0,0" StrokeThickness="3" Stroke="#ffaaaaaa" StrokeLineJoin="Round" Opacity="0.2" >
                                <Path.LayoutTransform>
                                    <ScaleTransform ScaleX=".15" ScaleY=".15" />
                                </Path.LayoutTransform>
                            </Path>
                            <DataTemplate.Triggers>
                                <!-- Clubs -->
                                <DataTrigger Binding="{Binding}">
                                    <DataTrigger.Value>
                                        <CardModel:Suit>Clubs</CardModel:Suit>
                                    </DataTrigger.Value>
                                    <Setter TargetName="SuitFigure" Property="Data" Value="M 87.39823,1.434783 c -25.66303,0 -46.46875,20.805729 -46.46875,46.468749 0,8.37613 2.21567,16.21354 6.09375,23 -0.21051,-0.003 -0.41382,-0.0312 -0.625,-0.0312 -25.66303,0 -46.46875026,20.805725 -46.46875026,46.468748 0,25.66301 20.80572026,46.46874 46.46875026,46.46874 11.22757,0 21.49901,-3.99621 29.53125,-10.625 -1.8903,16.14905 -9.36762,25.11364 -22.5625,29.0625 l 0,13.625 34.34375,0 10.71875,0 22.96875,0 0,-13.625 c -13.1949,-3.94886 -20.6722,-12.91345 -22.562503,-29.0625 8.032203,6.62879 18.334903,10.625 29.562503,10.625 25.6631,0 46.4688,-20.80573 46.4688,-46.46875 0,-25.663013 -20.8057,-46.468738 -46.4688,-46.468738 -0.2188,0 -0.4381,0.0282 -0.6562,0.0312 3.878,-6.78646 6.125,-14.62387 6.125,-23 0,-25.66302 -20.8057,-46.468749 -46.4688,-46.468749 z" />
                                </DataTrigger>
                                <!-- Diamonds -->
                                <DataTrigger Binding="{Binding}">
                                    <DataTrigger.Value>
                                        <CardModel:Suit>Diamonds</CardModel:Suit>
                                    </DataTrigger.Value>
                                    <Setter TargetName="SuitFigure" Property="Data" Value="M 14.01934,98.653544 87.21969,195.83238 160.77717,98.653544 87.21969,1.4747185 14.01934,98.653544 z" />
                                    <Setter TargetName="SuitFigure" Property="Fill" Value="#FFD00000" />
                                </DataTrigger>
                                <!-- Hearts -->
                                <DataTrigger Binding="{Binding}">
                                    <DataTrigger.Value>
                                        <CardModel:Suit>Hearts</CardModel:Suit>
                                    </DataTrigger.Value>
                                    <Setter TargetName="SuitFigure" Property="Data" Value="M 47.985376,19.966068 c -23.09573,-0.532652 -44.38247,18.659016 -46.22883,41.686845 -2.26447002,22.84094 9.77203,44.167297 23.93526,61.148957 18.6597,22.75756 39.86296,43.29418 61.60603,63.07045 C 111.84869,162.73239 137.07768,139.34762 157.0325,111.81114 168.12392,95.77446 176.96779,75.553697 171.80352,55.82187 166.56287,33.65704 143.28798,17.895283 120.75207,21.355962 107.37206,23.016424 94.980976,30.92423 87.735286,42.278567 79.533166,28.572302 63.963856,19.814462 47.985376,19.966068 z" />
                                    <Setter TargetName="SuitFigure" Property="Fill" Value="#FFD00000" />
                                </DataTrigger>
                                <!-- Spades -->
                                <DataTrigger Binding="{Binding}">
                                    <DataTrigger.Value>
                                        <CardModel:Suit>Spades</CardModel:Suit>
                                    </DataTrigger.Value>
                                    <Setter TargetName="SuitFigure" Property="Data" Value="M 87.343256,7.1223226 C 72.836756,19.172244 58.758606,31.742848 45.249506,44.903573 28.948686,61.455485 11.064796,78.359868 3.7807556,101.09108 c -2.57878,7.05865 -2.75811,14.39835 -1.84375,21.71875 2.79049,21.98176 24.5412404,37.89607 46.0937504,37.37499 9.94663,0.0737 19.93771,-3.04148 28.09375,-8.71875 -0.0189,0.15887 -0.0468,0.30679 -0.0625,0.46875 -1.64061,16.95273 -9.18188,26.26129 -22.71875,30.3125 l 0,13.625 34.34375,0 10.71875,0 22.968764,0 0,-13.625 c -13.53688,-4.05121 -21.07815,-13.35977 -22.718764,-30.3125 -0.0558,-0.57615 -0.12357,-1.11926 -0.21875,-1.65625 7.383404,5.26529 16.317804,8.38819 25.375014,8.875 21.79614,1.82812 44.71868,-13.09976 48.78125,-35.1875 3.45594,-17.52745 -5.28026,-34.827782 -15.5,-48.531247 C 136.91609,49.782746 111.75938,28.372835 87.343256,7.1223226 z" />
                                </DataTrigger>
                            </DataTemplate.Triggers>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>

                <TextBlock Text="{Binding Path=BaseCues.Rank, Converter={StaticResource RankConverter}}" FontSize="130" Foreground="Cornsilk" HorizontalAlignment="Center" FontFamily="Impact" Opacity="0.15" Margin="0,-14,0,0" />
            </DockPanel>
        </Grid>
        
        <!--Label Content="{Binding Path=Name}" Opacity="0.2" /-->

        <ItemsControl x:Name="Cards" >
            <ItemsControl.Style>
                <Style TargetType="ItemsControl">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding IsElevated}" Value="true">
                            <Setter Property="Effect">
                                <Setter.Value>
                                    <DropShadowEffect BlurRadius="14" Opacity="0.8" />
                                </Setter.Value>
                            </Setter>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </ItemsControl.Style>
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <Canvas />
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemContainerStyle>
                <Style TargetType="ContentPresenter">
                    <Setter Property="Canvas.Left" Value="{Binding Path=Location.X}" />
                    <Setter Property="Canvas.Top" Value="{Binding Path=Location.Y}" />
                    <Setter Property="Width" Value="{Binding Path=Size.Width}" />
                    <Setter Property="Height" Value="{Binding Path=Size.Height}" />
                </Style>
            </ItemsControl.ItemContainerStyle>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.Resources>
                            <ImageBrush x:Key="cardVisual">
                                <ImageBrush.ImageSource>
                                    <Binding Path="Visual" />
                                </ImageBrush.ImageSource>
                            </ImageBrush>
                        </Grid.Resources>
                        <Rectangle x:Name="HotCue" Fill="White" Style="{StaticResource cardSite}" Visibility="Hidden" >
                            <Rectangle.Effect>
                                <DropShadowEffect x:Name="Glow" ShadowDepth="0" BlurRadius="20" Color="LemonChiffon" Opacity="0" />
                            </Rectangle.Effect>
                        </Rectangle>
                        <Rectangle Fill="{StaticResource cardVisual}" Stroke="LightGray" Style="{StaticResource cardSite}" >
                            <Interactivity:Interaction.Behaviors>
                                <Behaviors:HotCueBehavior />
                            </Interactivity:Interaction.Behaviors>
                        </Rectangle>
                        <Rectangle x:Name="SelectionCue" Style="{StaticResource cardSite}" Visibility="Hidden" Fill="#80000080" IsHitTestVisible="false" />
                        <!--Label Content="{Binding Card}" /-->
                    </Grid>
                    <DataTemplate.Triggers>
                        <DataTrigger Binding="{Binding InHotState}" Value="True">
                            <DataTrigger.EnterActions>
                                <BeginStoryboard Storyboard="{StaticResource ShowHotCue}" />
                            </DataTrigger.EnterActions>
                            <DataTrigger.ExitActions>
                                <BeginStoryboard Storyboard="{StaticResource HideHotCue}" />
                            </DataTrigger.ExitActions>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding IsSelected}" Value="True" >
                            <Setter TargetName="SelectionCue" Property="Visibility" Value="Visible" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Hidden}" Value="True">
                            <Setter Property="Visibility" Value="Hidden" />
                        </DataTrigger>
                    </DataTemplate.Triggers>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </Canvas>
</UserControl>
